<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();//获得当前的项目根目录路径赋值给path
%>
<jsp:include page="/WEB-INF/jsp/common/header.jsp"></jsp:include>
<style>
    .pagelist {padding:10px 0; text-align:center;}
    .pagelist span,.pagelist a{ border-radius:3px; border:1px solid #dfdfdf;display:inline-block; padding:5px 12px;}
    .pagelist a{ margin:0 3px;}
    .pagelist select{border-radius:3px; border:1px solid #dfdfdf;display:inline-block; padding:5px 5px;}
    .current{ background:#09F; color:#FFF; border-color:#09F; margin:0 2px;}
    .pagelist a:hover{background:#09F; color:#FFF; border-color:#09F; }
    .pagelist label{ padding-left:15px; color:#999;}
    .pagelist label b{color:red; font-weight:normal; margin:0 3px;}
</style>
<body>
<!--nav start-->
<jsp:include page="/WEB-INF/jsp/common/nav.jsp"></jsp:include>
<!--inside content start-->
<div class="inside_wrap">
    <div class="inside_con">
        <div class="adr">
            <a href="">首页</a>&nbsp;>&nbsp;评论管理&nbsp;>&nbsp;我的评论
        </div>
        <div class="inside_box">
            <%--LEft--%>
            <jsp:include page="/WEB-INF/jsp/common/left.jsp"></jsp:include>
            <div class="ic_wrap fr">
                <form action="<%=path%>/comment/list" method="post" id="searchForm">
                    <input type="hidden" name="pageNum" id="pageNum">
                    <%--	<button type="button" onclick="location.href='${pageContext.request.contextPath}/pet/toAdd.action'" class="layui-btn  layui-btn-sm">新增</button>--%>
                    <div class="layui-form-mid">关键词:</div>
                    <div class="layui-input-inline" style="width: 100px;">
                        <input type="text" name="content" placeholder="评论内容" value="${requestScope.record.content}" style="height:33px;"  class="layui-input">
                    </div>


                    <%--   <input type="hidden" name="pageNum" id="pageNum" />--%>
                    <input type="hidden" name="pageSize" id="pageSize" value="${pageInfo.pageSize }">

                    <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm">查询</button>
                    <button id="delmany" class="layui-btn layui-btn-danger layui-btn-sm" type="button">批量删除</button>

                </form>

                <table class="layui-table" lay-size="sm">

                    <thead>
                    <tr>
                        <th><input type="checkbox" onclick="checkAll()" id="selectall"/></th>
                        <th>评论帖子</th>
                        <th>评论人</th>
                        <th>评论内容</th>
                        <th>评论时间</th>

                        <th style="text-align: center;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:if test="${requestScope.pageInfo.list!=null}">
                        <c:forEach items="${requestScope.pageInfo.list}" var="row">
                            <tr  >
                                <td ><input type="checkbox" name="id" value="${row.id }"/></td>
                                <td class="rowid" style="display: none;">${row.id}</td>
                                <td><a href="<%=path%>/tiezi/detail?id=${row.tiezi.id}" target="_blank">${row.tiezi.title}</a></td>

                                <td>${row.user.nick_name}</td>
                                <td>${row.content}</td>
                                       <td>
                                           <fmt:formatDate value="${row.create_time}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                       </td>

                                <td style="text-align: center" >

                                    <a  class="layui-btn layui-btn-danger layui-btn-sm  layui-delete"  href="javascript:void(0)" style="text-decoration:none">
                                        <i class="layui-icon">&#xe640;</i>
                                    </a>
                                        <%--	<a  class="layui-btn layui-btn-danger layui-btn-sm"  href="javascript:deleteRow('${row.id}','${row.photo}')" style="text-decoration:none">
                                                <i class="layui-icon">&#xe640;</i>
                                            </a>--%>
                                </td>

                            </tr>
                        </c:forEach>

                    </c:if>
                    </tbody>
                </table>


                <c:if test="${requestScope.pageInfo.list.size()>0}">
                    <div  class="pagelist">
                        共有${pageInfo.total }条记录共${pageInfo.pages }页，每页
                        <select name="pageSize" onchange="changePageSize(this.value)" style="width: 50px;">
                            <option value="5" ${pageInfo.pageSize==5?"selected":"" }>5</option>
                            <option value="10"  ${pageInfo.pageSize==10?"selected":"" }>10</option>
                            <option value="15"  ${pageInfo.pageSize==15?"selected":"" }>15</option>
                            <option value="20"   ${pageInfo.pageSize==20?"selected":"" }>20</option>
                        </select>

                        <a  href="javascript:doPage(1)">首页</a>

                        <c:if test="${pageInfo.pageNum>pageInfo.pages}">
                            <a href="javascript:doPage(${requestScope.pageInfo.pageNum -1})">上一页</a>
                        </c:if>

                        <c:if test="${pageInfo.pageNum<pageInfo.pages}">
                            <a href="javascript:doPage(${requestScope.pageInfo.pageNum +1})">下一页</a>
                        </c:if>
                        <a href="javascript:doPage(${requestScope.pageInfo.pages})">尾页</a>

                        转到<select name="pageNum" onchange="doPage(this.value)" style="width: 50px;">
                        <c:forEach begin="1" end="${pageInfo.pages }" var="i">
                            <option class="option" value=${i }  ${pageInfo.pageNum==i?"selected":"" }>${i }</option>
                        </c:forEach>

                    </select>


                    </div>
                </c:if>



            </div>
            <div class="clear"></div>
        </div>
    </div>
</div>
<!--footer start-->
<jsp:include page="/WEB-INF/jsp/common/footer.jsp"></jsp:include>
<script src="<%=path%>/static/js/jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="<%=path%>/static/js/jquery.SuperSlide.2.1.js" type="text/javascript"></script>
<script src="<%=path%>/static/js/common.js"></script>
<script src="${pageContext.request.contextPath}/static/layuiadmin/layui/layui.js"></script>
<script>

    function doPage(pageNo) {
        document.getElementById("pageNum").value = pageNo;
        document.getElementById("searchForm").submit();
    }
    function changePageSize(cur_pageSize){
        document.getElementById("pageSize").value=cur_pageSize;
        document.getElementById("searchForm").submit();//表单提交
    }
    //Demo
    layui.use(['form','upload','jquery'], function(){
        var $ = layui.$
            ,upload=layui.upload
            ,form = layui.form;

        $("#delmany").click(function () {
            var checkbox=false;//默认复选框为空
            $("input[name='id']").each(function(){//获取复选框节点id
                if (this.checked==true) {
                    checkbox=true;  //已勾选
                }
            });

            if(checkbox) {
                var obj = document.getElementsByName("id");//将复选框定义成一个jquery对象
                var check_val = [];//定义一个数组
                for ( var k in obj) {//k相当于i,往这个jquery对象添加勾选的id;
                    if (obj[k].checked) //选中的都放进 数组里
                        check_val.push(obj[k].value);
                }
                layer.confirm('确认批量删除该记录吗?', { btn: ['是','否'],btn1: function(){
                        $.ajax({//利用ajax发出请求
                            type:"post",//post类型
                            /*dataType:"text",
                            data:{"ids":check_val},*/
                            url:"${pageContext.request.contextPath}/comment/deletemany?ids="+check_val,
                            success:function(data){//删除成功后，deleteMany会返回一个"ok";
                                if(data=="ok"){
                                    layer.msg('删除成功', {
                                        icon: 1,
                                        time: 1000 //2秒关闭（如果不配置，默认是3秒）
                                    }, function(){
                                        document.location.reload();
                                    });


                                }

                            }
                        });

                    },
                    btn2: function(index){
                        layer.close(index);
                    }
                })



            }else {
                layer.alert("你没有选中任何的记录信息！");
                /*	layer.msg("你没有选中任何的记录信息");*/
            }
        });

        $(".layui-delete").on('click',function(){


            var rowid=$(this).parents("tr").find(".rowid").text();
            var filename=$(this).parents("tr").find(".filename").text();
            /*	alert(filename);*/
            layer.confirm('确认删除本条记录吗?', { btn: ['是','否'],btn1: function(){
                    $.ajax({
                        url:"${pageContext.request.contextPath}/comment/delete",
                        type: "POST",
                        data:{'id':rowid,'filename':filename},
                        success:function (data) {
                            console.log(data);
                            if(data=="ok")	{
                                layer.msg('删除成功',{
                                    offset:['50%'],
                                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                                },function(){
                                    window.location.href="${pageContext.request.contextPath}/comment/list";//相当于刷新界面
                                });

                            }else{
                                layer.msg('删除失败',{
                                    offset:['50%'],
                                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                                },function(){
                                    window.location.href="${pageContext.request.contextPath}/comment/list";//相当于刷新界面
                                });
                            }
                        }
                    });
                },
                btn2: function(index){
                    layer.close(index);
                }
            })

        });


        var uploadInst = upload.render({

            elem: '#headImg'
            , url: '${pageContext.request.contextPath}/utils/add.action'
            ,method: 'post'
            , size: 5000

            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                //打印后台传回的地址: 把地址放入一个隐藏的input中, 和表单一起提交到后台, 此处略..
                /*   console.log(res.data.src);*/
                /* window.parent.uploadHeadImage(res.data.src); */
                console.log(res.data.src);
                $("#photo").val(res.data.src);
                var demoText = $('#demoText');
                demoText.html('<span style="color: #8f8f8f;">上传成功!!!</span>');
            }
            , error: function (res) {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }

        });


    });
</script>
</body>
</html>
